﻿
CREATE PROCEDURE [dbo].[proc_Index_Notice_GetList]
	(
	@UserName nvarchar(50)
	)
AS
	Begin
	
/*******************单位通知********************/	
		Declare @CompanyId int
		Set @CompanyId = (select Companyid from aspnet_Users where username=@UserName)
		select * from (
		Select
			top 5
			N.Id,
			N.NId,
			N.Fid,
			(select title from notice_category where id=N.fid) as category,
			N.Title,
			N.Content,
			N.UpName,
			N.IsAll,
			N.IsDing,
			N.CreateTime,
			N.UpTime 
		--From Notice N Where N.CompanyId=@CompanyId Order By N.IsDing DESC,UpTime DESC
		From Notice N Where 
		(N.CompanyId=@CompanyId OR N.CompanyIdList LIKE '%{' + CONVERT(VARCHAR(5),@CompanyId) + '}%') 
		Order By UpTime DESC) as a
		order by IsDing DESC
/*******************单位通知END********************/
		
/*******************集团通知********************/
		select * from (
		Select
			top 5
			N.Id,
			N.NId,
			N.Fid,
			(select title from notice_category where id=N.fid) as category,
			N.Title,
			N.Content,
			N.UpName,
			N.IsAll,
			N.IsDing,
			N.CreateTime,
			N.UpTime 
		From Notice N Where IsAll=1 Order By CreateTime DESC) as a
		order by IsDing DESC
/*******************集团通知END********************/		
		
/*******************客户审核********************/		
	Select top 5 Id,CustomerId,isnull(CustomerName,'') as CustomerName,AuditDate
	From Customer_AuditLog
	Where (SalesName=@UserName Or AuditUser=@UserName)
	Order By AuditDate Desc	
		
/*******************客户审核END********************/		
		
/*******************今天需要联系的客户********************/		
Select	top 10 	Id,
	CustomerId,
	IsNull((Select CustomerName From Customer Where CustomerId=Customer_Remind.CustomerId And ProtectName=@UserName),'...') As CustomerName,
	RemindDate,
	UserName,
	UpTime From Customer_Remind
	where username=@username and Convert(varchar(10),UpTime,23)=Convert(varchar(10),GetDate(),23)		
/*******************今天需要联系的客户END********************/			
		
		
/*******************成单退回记录********************/			
Select
	 top 10
	 
	Id,
	OId,
	OrderId,
	CustomerId,
	isnull((Select CustomerName From Customer Where CustomerId=Orders.CustomerId),'...') As CustomerName,
	ContactPerson,
	ContactPhone,
	UserName,
	EName,
	FixtureDate,
	Description,
	Aggregateamount,
	isnull(Proceeds,0) as Proceeds,
	CreateDate,
	isnull(CompanyId,'0') As CompanyId,
	isnull(DepartmentId,'0') As DepartmentId,
	FinanceFlag,
	PaymentTypeId,
	IsReason,
	TichengFlag,
	IsNull(TiCheng,0) as TiCheng
	From Orders Where UserName=@UserName and IsReason=1 Order By Id DESC		
/*******************成单退回记录END********************/		
		
		
	End